package rullekake.facade;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import rullekake.entities.Users;

/**
 * Utvider AbstractFacade for Users.
 * Tar seg av peristence for Users-objekter
 *
 */

@Stateless
public class UsersFacade extends AbstractFacade<Users> {
    @PersistenceContext(unitName = "SystemeringPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public UsersFacade() {
        super(Users.class);
    }

    /**
     * Finner brukerentitet med gitt brukernavn
     * @param username brukernavn
     * @return bruker
     */

    public Users findByUsername(String username) {
        javax.persistence.Query q = getEntityManager().createNamedQuery("Users.findByUsername");
        q.setParameter("username", username);
        return (Users)q.getSingleResult();
    }    
}
